package com.atguigu.day11.exer.e4;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/12 16:55
 * @注释 对各个图形进行判断和排序
 */
public class GraphicTools {
    /**
     * 判断各个图形的面积大小
     * @param s1
     * @param s2
     * @return
     */
    public static int compare(Graphic s1, Graphic s2) {
        if (s1.area() > s2.area()){
            return 1;
        }else if (s1.area() < s2.area()){
            return -1;
        }else {
            return 0;
        }
    }

    /**
     * 判断各个图形的面积和周长是否都相等
     * @param s1
     * @param s2
     * @return
     */
    public static boolean equals(Graphic s1, Graphic s2){
        if (s1.area() == s2.area() && s1.perimeter() == s2.perimeter()){
            return true;
        }
        return false;
    }

    /**
     * 对所有图形按照面积从小到大排序
     * @param arr
     */
    public static void sort(Graphic[] arr){
        for (int i = 0; i < arr.length - 1; i++){
            for (int j = 0; j < arr.length - 1; j++){
                if (arr[j].area() > arr[j + 1].area()){
                    Graphic temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
    }

    /**
     * 遍历各个图形的详细信息
     * @param massage
     * @param arr
     */
    public static void print(String massage,Graphic[] arr){
        System.out.println(massage);
        for (int i = 0; i < arr.length; i++){
            System.out.println(arr[i]);
        }
    }
}
